/*******************************************************************************

[Last updated: June 4th, 2024]

This script outlines the workflow for each component script in the 
endline analysis pipeline. It should be executed before running any component script.

The script is organized as follows:

	Part A: Set up Stata Workspace
	Part B: Run the data analysis in sequence
	
Each subscript includes detailed information about its specific purpose.

*******************************************************************************/


* Part A: Establish path directory ---------------------------------------------

clear all

	* Parameter for updates
	global update			"Yes"

	* Randomization roster & partial POST data
	gl e_data 			${FilePath12}				
	gl rand				${e_data}\dta\clean\SitD_Clean_EndXWalk		
	gl post_cleaned 	${e_data}\dta\clean\SitD_Clean_EndPost.dta					
	gl demo 			${FilePath4}												
	
	gl rand_cleaned 	${e_data}\dta\clean\SitD_Clean_EndXWalk_cleaned
	
	* Clean PRE data set to get some data
	gl pre_coded		${e_data}\dta\coding\pre\coded\SitD_Clean_EndPreCoded				
	gl pre_coded_int 	${e_data}\dta\coding\pre\coded\SitD_Clean_EndPreCodedInterpretations
	gl pre_coded_act 	${e_data}\dta\coding\pre\coded\SitD_Clean_EndPreCodedActions		
	gl pre_out			${FilePath15}
	
	* Input from cleaned assesment data
	gl o_data 			${FilePath13}
	gl out_pre			${o_data}\assessment_pre
	gl out_pos			${o_data}\assessment_pos
	gl out_rub			${o_data}\assessment_rub
	
	* Pre-training Admin data
	gl pre_admin 		${FilePath16}
	
	* Programmatic macro for repetitive tas
	global functions	"${FilePath2}/function/function_admin__functions.do"
	global notes		"${FilePath2}/function/function_admin__notes.do"
		
	do "$functions"
	do "$notes"
		
	* Version
	gl version online
	
	* Covariate settings
		
		gl add_officer			experience dblack dhispanic dwhite dmale
		gl add_covariates 		pre_arrest_con_cop pre_prs_score_w_arrs pre_days_iod
		gl officer_baseline 	$add_officer $add_covariates
		
		gl consideration_demo 	experience dblack dhispanic dwhite dmale
		gl consideration_base	pre_arrest_con_cop pre_prs_score_w_arrs pre_days_iod
		gl consideration		$consideration_base $consideration_demo

	* Allow individual run (after loading the parameters to memory)
	gl	individual_run 		"Yes"

* Part B: Analysis -------------------------------------------------------------
if "$update" == "yes" {
	
	* Build data for analysis
	do  "${FilePath20}/build/build_0_clean_survey_data.do"
	
	* Analysis sequence (must run one after the other)
		
		* Regression
		do  "${FilePath20}/analysis/analysis_1_regression.do"
		
		* FDR adjustment
		do 	"${FilePath20}/analysis/analysis_2_FDR.do"
		
		* Making Latex table
		do 	"${FilePath20}/analysis/analysis_3_Latex.do"
}


